/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.academik.validation;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import org.academik.controller.InscripcionBean;
import org.academik.util.FacesUtil;

/**
 *
 * @author Javier
 */
@FacesValidator("alumnosValidator")
public class AlumnosValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        InscripcionBean e = (InscripcionBean) FacesUtil.getBean("inscripcionBean");
        if (e.getAlumnos().isEmpty()) {
            FacesMessage msg = new FacesMessage("Error:", "Agregue uno o mas alumnos");
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
            throw new ValidatorException(msg);
        }
    }    
}
